<template>
  <div class="all-job-resume">
    <div class="all-job-resume-head">
      <el-col :span="23">
        <span class="all-job-resume-line"></span>
        教育经历
        <span class="all-job-resume-sub-text">必填</span>
      </el-col>
      <el-col :span="1" v-if="data.length < 10">
        <i class="el-icon-circle-plus plus-add" @click="addContent"></i>
      </el-col>
    </div>

    <education-experience-list
      v-for="(item,index) in data"
      :key="index"
      :data="item"
      :educationType="educationType"
      :form="form"
      @on-pitch="cancel"
    ></education-experience-list>

    <div class="edit-content" v-if="form.sta == 5 && form.editSta == -1">
      <div class="all-job-resume">
        <el-form label-width="100px" label-position="right">
          <el-row>
            <el-col :span="12">
              <el-form-item label="学校名称">
                <el-input class="theme-input all-input" v-model="params.school"></el-input>
              </el-form-item>
              <el-form-item label="学历">
                <el-select class="all-input" v-model="params.academicId" placeholder="请从最高学历开始填写">
                  <el-option
                    v-for="(item,index) in educationType"
                    :key="index"
                    :value="item.id"
                    :label="item.content"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="11" :offset="1">
              <el-form-item label="所学专业">
                <el-input class="theme-input all-input" v-model="params.major"></el-input>
              </el-form-item>
              <el-form-item label="在读时间">
                <el-date-picker
                  :editable="false"
                  class="resume-datepicker"
                  value-format="yyyy-MM"
                  type="monthrange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  v-model="params.time"
              
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item class="form-button-right">
            <el-button class="ghost-button" @click="cancel">取消</el-button>
            <el-button class="submit-button" @click="onSubmit">确认</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import educationExperienceList from './list/education-experience-list'
export default {
  props: ['form', 'educationType', 'data'],
  data() {
    return {
      params: {
        id: '',
        school: '',
        academicId: '',
        major: '',
        time: []
      },
      pickerOptions: {
        shortcuts: [
          {
            text: '今年至今',
            onClick(picker) {
              const end = new Date()
              const start = new Date(new Date().getFullYear(), 0)
              picker.$emit('pick', [start, end])
            }
          }
        ]
      }
    }
  },
  methods: {
    check() {
      if (
        this.params.school == '' ||
        this.params.academicId == '' ||
        this.params.major == '' ||
        this.params.time == ''
      ) {
        _g.message('数据不能为空', 'warning')
        return false
      }
      return true
    },
    addContent() {
      //点击添加按钮
      this.form.sta = 5
      this.form.editSta = -1
    },
    cancel() {
      this.$emit('on-pitch', true)
      this.form.sta = -1
      this.form.editSta = -1
    },
    onSubmit() {
      if (!this.check()) return false
      let params = {
        id: this.params.id,
        school: this.params.school,
        academicId: this.params.academicId,
        major: this.params.major,
        startTime: this.params.time[0],
        endTime: this.params.time[1]
      }
      _g.apiPost('/talent/updateEducationExp.do ', params).then(res => {
        _g.toMessage(res)
        this.cancel()
        this.emptyData()
      })
    },
    emptyData() {
      this.params.id = ''
      this.params.school = ''
      this.params.academicId = ''
      this.params.major = ''
      this.params.time = []
    }
  },
  components: {
    educationExperienceList
  }
}
</script>

<style lang="scss" scoped>
</style>
